#include "utility.h"
#include "stdio.h"
int CM_Atoi(char* source,int* integer)
{
	int offset1,offset2,num;
	int signedflag;//+为1 -为0
 
	if(source == NULL || integer == NULL)
	{
		return 0;
	}
 
	offset1 = 0;
	offset2 = 0;
	num = 0;
 
	while(*source <= 32)//去除首部空格 \r \n \t \r 等异常字符
	{
		source++;
		offset1++;
	}
 
	signedflag = 1;//默认为+
	if(*source == '+')
	{
		signedflag = 1;
		source++;
		offset1++;
	}
	else if(*source == '-')
	{
		signedflag = 0;
		source++;
		offset1++;
	}
 
	while(*source != '\0' && *source >= '0' && *source <= '9')
	{
		num = *source- '0' + num*10;
		source++;
		offset2++;
	}
 
	if(signedflag == 0)
	{
		num = -num;
	}
 
	if(offset2)
	{
		*integer = num;
		return offset1+offset2;
	}
	else
	{
		return 0;
	}
}
